package com.markerhub.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.markerhub.common.lang.Result;
import com.markerhub.entity.TFacilityFunction;
import com.markerhub.povo.TFacilityFunctionVo;
import com.markerhub.service.TFacilityFunctionService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.nio.file.Path;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 刘佳明
 * @since 2021-12-27
 */
@Controller
@RequestMapping("/tFacilityFunction")
public class TFacilityFunctionController {

    @Autowired
    TFacilityFunctionService tFacilityFunctionService;

    @RequestMapping("/FunctionSubim")
    @PreAuthorize("hasAuthority('sys:facility:function')")
    @ResponseBody
    /*@Validated @RequestBody @RequestParam(value = "tFacilityFunctions",required=false) */
    public Result FunctionSubim(@RequestBody List<TFacilityFunctionVo> tFacilityFunctions){
        for (TFacilityFunctionVo tFacilityFunction:tFacilityFunctions) {
            //System.out.println("tFacilityFunction== >>> "+tFacilityFunction);
            if (tFacilityFunction.getTab0()==true){
                tFacilityFunction.setFunctionStatus(1);
            }else {
                tFacilityFunction.setFunctionStatus(0);
            }
            boolean b = tFacilityFunctionService.updateById(tFacilityFunction);
        }
        return Result.succ(tFacilityFunctions);
    }
    @RequestMapping("/getinfo/{beseid}")
    @PreAuthorize("hasAuthority('sys:facility:getinfo')")
    @ResponseBody
    /*@Validated @RequestBody @RequestParam(value = "tFacilityFunctions",required=false) */
    public Result getinfo(@PathVariable("beseid") String beseid){
        List<TFacilityFunction> baseid = tFacilityFunctionService.list(new QueryWrapper<TFacilityFunction>().eq("baseid", beseid));
        return Result.succ(baseid);
    }


}

